
// <author>Ameer Sheikh</author>

exports.GALogger =  Core.Class.singleton({
	
	classname : 'GALogger',
	_logThreshold: 0,
	initialize: function(){
		this._gameName = GAConfigurations.getGameName();
	},
	setLogThreshold: function(myThreshhold)
	{
	    this._logThreshold = myThreshhold;
	},
	
	log: function (myString)
	{
		//by Default logs in verbose mode.
		if(isValidString(myString))
		{
			this.logWithLevel(myString, LOG_LEVEL.LOG_ALL);
		}
	},
		
	logCritical: function (myString)
	{
		//by Default logs in FATAL ERROR mode.
		if(isValidString(myString))
		{
			this.logWithLevel(myString, LOG_LEVEL.LOG_FATAL);
		}
	},
	
	logWithLevel: function(myString, myLevel, isUILog)
	{
		try
		{
		    var localFormat = null;
			
            if(!isValidNumber(myLevel))
            {
                myLevel = LOG_LEVEL.LOG_ALL;
            }
            
		    if (myLevel >= this._logThreshold)
		    {
		        return;
		    }
			
            
            if(!isValidString(myString)) {
                myString = "Not a valid string for Logging";
                return;
            }
            
		    localFormat = 'GALogger [ '+this._gameName+' Log Level: '+this.getLevelString()+']: '+myString+'\n';
		    
			if(isUILog != null && isUILog == true)
			{
				UIFactory.showToast(myString);
			}
			else
			{
				console.log(localFormat);
			}
		}
		catch(exception)
		{
			console.log('Logger: EXCEPTION Occurred in GALogger::logWithLevel. Reason: ' + exception.toString());
		}
	},
	
	getLevelString :function()
	{
		switch(this._logThreshold)
		{
			case LOG_LEVEL.LOG_ALL:
				return 'log all';
				break;
			case LOG_LEVEL.LOG_VERBOSE:
				return 'verbose log';
				break;
			case LOG_LEVEL.LOG_DEBUG:
				return 'debug';
				break;
			case LOG_LEVEL.LOG_NONFATAL_ERROR:
				return 'non-fatal error';
				break;
			case LOG_LEVEL.LOG_EXCEPTION:
				return 'exception';
				break;
			case LOG_LEVEL.LOG_FATAL:
				return 'fatal error';
				break;
			case LOG_LEVEL.LOG_SILENT:
				return 'silent log';
				break;
			default:
				return 'Unknown level';
		}
	}
	
});